package com.gxa.clientproduct.service.impl;


import com.gxa.clientproduct.mapper.ProductMapper;
import com.gxa.clientproduct.pojo.Product;
import com.gxa.clientproduct.service.ProductService;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: fenglin
 * @Date:2020/11/12 14:42
 * @Version 1.0
 */
@Service("productService")
public class ProductServiceImpl  implements ProductService {

    @Resource
    ProductMapper productMapper;

    @Override
    public List<Product> findAll(){

        Example example = new Example(Product.class);

        Example.Criteria criteria = example.createCriteria();
//        criteria.orEqualTo("prostate",prostate);
        criteria.orEqualTo("prostate",0);
        criteria.orEqualTo("prostate",1);


        return productMapper.selectByExample(example);
    }

    @Override
    public List<Product> findAllRecovery() {

        Example example = new Example(Product.class);

        Example.Criteria criteria = example.createCriteria();
//        criteria.orEqualTo("prostate",prostate);
        criteria.andEqualTo("prostate",2);


        return productMapper.selectByExample(example);
    }

    @Override
    public List<Product> fandNameAndNum(String name, String num,Integer classify) {
        Example example = new Example(Product.class);
        Example.Criteria criteria = example.createCriteria();
        if (name!=null){
            criteria.andLike("name","%"+name+"%");
        }
        if (num!=null){
            criteria.andLike("num","%"+num+"%");
        }
        if (classify.equals("1")){
            criteria.andEqualTo("classify","1");
        }
        if (classify.equals("2")){
            criteria.andEqualTo("classify","2");

        }
        if (classify.equals("3")){
            criteria.andEqualTo("classify","3");

        }

        return productMapper.selectByExample(example);
    }

    @Override
    public Product findSysNum(String sysNum) {

        Example example = new Example(Product.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("sysnum",sysNum);

        return productMapper.selectOneByExample(example);
    }


    @Override
    public int del(Product product) {
        return productMapper.delete(product);
    }

    @Override
    public int state(Product product) {
        return productMapper.updateByPrimaryKeySelective(product);
    }

    @Override
    public int productAdd(Product product) {
        return productMapper.insertSelective(product);
    }

    @Override
    public int productUpdate(Product product) {
        return productMapper.updateByPrimaryKey(product);
    }
}
